package io.polly.secure;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;

/**
 * @author ldz
 * @version V1.0
 * @title: ForkJoinMain
 * @description: TODO(用一句话描述该文件做什么)
 * @date: 2022/4/1 16:07
 */

public class ForkJoinMain {


    public static void main(String[] args) {

        Integer[] randomArr= randomInteger(1000000);
        ArrayList<Integer> list = new ArrayList<>(Arrays.asList(randomArr));
        ForkJoinPool forkJoinPool = new ForkJoinPool(4);
        ForkJoinTask task = new ForkJoinTask(0, list.size(),list);
        Integer sum = forkJoinPool.invoke(task);
        System.out.printf("sum:"+sum);
        forkJoinPool.shutdown();

    }
    private static Integer[] randomInteger(int size){
        Integer[] arr =new Integer[size];
        for (int i=0; i < arr.length; i++){
            arr[i] = i;
        }
        return arr;
    }
}
